<?php
class Model_destination extends CI_Model{
	protected $_region = "tbl_regions";
	protected $_destination = "tbl_destinations";
	public function __construct(){
		parent::__construct();
		$this->load->database();
	}
	public function listregion(){
		return $this->db->get($this->_region)->result_array();
	}
	public function checkdestina($from,$to){
		$this->db->where("fromid",$from);
		$this->db->where("toid",$to);
		return $this->db->count_all_results($this->_destination);
	}
	public function setdestion($from,$to){
		$this->db->where("fromid",$from);
		$this->db->where("toid",$to);
		return $this->db->get($this->_destination)->row_array();;
	}
	public function update($data,$from,$to){
		$this->db->where("fromid",$from);
		$this->db->where("toid",$to);
		$this->db->update($this->_destination,$data);
	}
	public function add($data){
		$this->db->insert($this->_destination,$data);
	}
	public function getregion($id){
		$this->db->where("region_id !=",$id);
		return $this->db->get($this->_region)->result_array();
	}
	public function deldestina($id,$where){
		$delete = implode(" and toid != ",$where);
		$sql = "delete from $this->_destination where toid != ".$delete." and fromid = '$id'";
		$this->db->query($sql);
	}
	public function getdata($id){
		$this->db->where("region_id",$id);
		return $this->db->get($this->_region)->row_array();
	}
	public function getdestina($id){
		$this->db->where("fromid",$id);
		return $this->db->get($this->_destination)->result_array();
	}
}